<template>
	<view>
		<view class="image_content">
			<swiper :autoplay="true" :interval="5000" :duration="1000" :circular='true' indicator-dots="true" indicator-color="#999999"
			 indicator-active-color="#e4e4e4" duration="1000" class="swiperBox">
				<swiper-item v-for="(item) in bannerList" :key='item.id' @click="openLink(item.link)">
					<view class="swiper-item">
						<image style="width: 100%; height: 370rpx;" :src="item.url" lazy-load mode="scaleToFill"></image>
					</view>
				</swiper-item>
			</swiper>
		</view>
		<view class="ten"></view>
		<view class="nav_content">
			<view v-for="(i,index) in IndexClassList" :key='i.id' @tap="openClass(i)" class="nav_box">
				<view class="nav_img">
					<image style="width: 100%; height: 100%;" :src="i.url" lazy-load mode="scaleToFill" />
				</view>
				<view class="nav_text">
					{{ i.name }}
				</view>
			</view>
		</view>
		
		<view class="newNotice" @click="gitNotiuce">
			<view class="newNoticeLeft">
				<view class="newIcon">
					<image src="../../static/images/index/ico_01.png" mode="scaleToFill" style="width: 100%; height: 100%;" />
				</view>
				<view class="NewTitle">最新通知</view>
				<view class="New_block"></view>
				<view class="NewMsg" v-if="listData.msg">{{listData.msg.substring(0,18)}}</view>
			</view>
			<view class="newNoticeRight">
				<image src="../../static/images/index/btn_12.png" mode="scaleToFill" style="width: 100%; height: 100%;"></image>
			</view>
			<view v-if="listData.has_new == 1" class="dian">.</view>
		</view>
		<view class="news_content">
			<view class="title_left">
				<view class="color_block"></view>
				<view class="text">最新资讯</view>
			</view>
		
		</view>
		<scroll-view scroll-y="true" style="height: 100%;">
			<ListItem :list='newslist' @noticeDetail='noticeDetail' />
		</scroll-view>
		<!-- 弹出层 -->
		<view class="" v-if="vers">
			<view class="popup"></view>
			<view class="popup-info">
				<view class="top">发现新版本</view>
				<view class="content">
					<view class="con-top">更新内容</view>
					<view class="con-center">
						<rich-text :nodes="content"></rich-text>
					</view>
				</view>
				<view class="button">
					<view class="cancel" @click="cancel">取消</view>
					<view class="update" @click="update">更新</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import ListItem from '../../components/index/list_item.vue'
	import uniLoadMore from '../../components/uni-load-more/uni-load-more.vue'
	
		
	export default {
		components: {
			ListItem,
			uniLoadMore
		},
		data() {
			return {
				vers: false,
				oldversion: '',
				content: '',
				phoneData: [],
				isupdate: true,
				bannerList: [], //banner图片
				newslist: [], //新闻列表
				page: 1,
				limit: 5,
				IndexClassList: [],
				status: '',
				contentText: {
					contentdown: '上拉加载更多',
					contentrefresh: '',
					contentnomore: '没有更多'
				},
				isEnd: false, //isEnd用于判断是否还有数据，没有数组停止数组请求
				triggered: false,
				_freshing: false,
				listData: '',
				scrollTop: 0,
				
				loginFlag:false,
				banners:[],
				classes:[],
				
			}
		},
		onShow() {
			this.isLogin();
		},
		onLoad() {
			this.fetchData();
			this.getList();
		},
		onReady() {
			
		},
		methods: {
			isLogin(){
				uni.getStorage({
					key:"token",
					success: (res) => {
						// console.log(res)
						if(res!=null){
							this.loginFlag = true
						}
					}
				})
				
				if(this.loginFlag==false){
					uni.navigateTo({
						url:'/pages/login/login'
					})
				}
			},
		//获取页面数据
		fetchData(){
			this.fetchBanners();
			this.fetchIndexClass();
		},
		//获取轮播图
		fetchBanners(){
			let owner_info = uni.getStorageSync('owner_info')
			console.log(owner_info)
			this.$request({
				url:'/admin/system/SysStatic/findStatic/banner',
				method:'GET',
				
				}).then(res=>{
				console.log(res)
				this.bannerList = res.data
			})
		},
		//获取按钮图标
		fetchIndexClass(){
			this.$request({
				url:'/admin/system/SysStatic/findStatic/indexClass',
				method:'GET',
				
				}).then(res=>{
				console.log(res)
				this.IndexClassList = res.data
			})
		},
		//跳转按钮
		openClass(data) {
			let myInfo = uni.getStorageSync('myInfo');
			let owner_info = uni.getStorageSync('owner_info');
			// const notice = data.path.indexOf("notice/notice");//社区新闻不需要登录
			// if(data.type === "outsideurl"){
			// 	let p = encodeURIComponent(data.path)
			// 	uni.navigateTo({
			// 		url: `/pages/webview/index?path=${p}`
			// 	})
			// }else if(data.type==="phone"){
			// 	uni.makePhoneCall({
			// 		phoneNumber: data.path,
			// 		success() {}
			// 	})	
			// }
			// else if (notice>1) {
			// 	uni.navigateTo({
			// 		url: "/"+data.path
			// 	})
			// }else
			 if(!myInfo ){
				this.gologin();
			} else {
				if (owner_info) {
					console.log(data.path)
					uni.navigateTo({
						url: data.path
					})
				}else {
					uni.navigateTo({
						url: '/pages/my/boundUSER'
					})
				}
			}
		},
		
		
		//获取列表
			getList() {
				if (this.isEnd) {
					return
				}
				this.$request({
					url: '/admin/system/sysActivity/'+this.page+'/'+this.limit,
					method: 'GET',
				}).then((res) => {
					console.log(res);
					this.newslist = res.data.records;
					if (res.data.records.length <= 0) {
						this.isEnd = true;
						this.status = 'noMore'
					} else {
						//this.page++
					}
				});
			},
		//method
		},
		
		
	}
</script>

<style lang="scss" scoped>
	.image_content {
		width: 100%;
		height: 370rpx;
		.swiperBox {
			width: 100%;
			height: 100%;
			z-index: 99;
		}
	}

	/deep/ uni-swiper .uni-swiper-dots-horizontal {
		bottom: 50rpx;
	}

	/deep/ .uni-swiper-dot {
		opacity: 0.8;
		width: 12rpx;
		height: 12rpx;
	}

	/deep/ .uni-swiper-dot-active {
		width: 48rpx;
		height: 12rpx;
		border-radius: 6rpx;
	}

	.nav_content {
		display: flex;
		width: 750rpx;
		align-items: center;
		// position: absolute;
		flex-wrap: wrap;
		// background-color: #FFFFFF;
		// justify-content: space-around;
		// padding: 30rpx 0 0 30rpx;
		// padding: 30rpx 30rpx 0 30rpx;
		padding-top: 30rpx;
		align-content: flex-start;
		flex-flow: row wrap;
	}

	.nav_box {
		// padding-right: 70rpx;
		// padding-bottom: 10rpx;
		 flex: 0 0 25%;
		 margin-bottom: 10px;
	}
	.nav_img {
		margin: 0 auto;
		width: 88rpx;
		height: 74rpx;
	}

	.nav_text {
		font-size: 32rpx;
		color: #262626;
		margin-top: 10rpx;
		text-align: center;
		width: 100%;
	}


	.newNotice {
		width: 93%;
		margin: 0 auto;
		height: 80rpx;
		background-color: #f5faf8;
		border-radius: 8rpx;
		// margin-top: 220rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		// position: relative;

		.newNoticeLeft {
			margin-left: 20rpx;
			width: 100%;
			height: 100%;
			display: flex;
			align-items: center;
			font-size: 26rpx;

			.newIcon {
				width: 48rpx;
				height: 48rpx;
			}

			.NewTitle {
				color: #323232;
				margin-left: 14rpx;
				margin-right: 20rpx;
				font-size: 26rpx;
			}

			.NewMsg {
				color: #808080;
				font-size: 26rpx;
				margin-left: 20rpx;
			}
			.New_block {
				width: 1rpx;
				height: 26rpx;
				background-color: #808080;
				border-radius: 1rpx;
			}
		}

		.newNoticeRight {
			width: 36rpx;
			height: 36rpx;
			margin-right: 12rpx;
			// background-color: #007AFF;
		}

		.dian {
			color: red;
			position: absolute;
			right: 60rpx;
			top: 14rpx;
			z-index: 999;
		}
	}

	.news_content {
		width: 93%;
		margin: 0 auto;
		// border-top: 1px solid #e6e6e6;
		margin-top: 46rpx;
		display: flex;
		justify-content: space-between;

		// padding-top: 34rpx;
		.title_left {
			display: flex;
			align-items: center;

			.color_block {
				width: 8rpx;
				height: 30rpx;
				background-color: #4699ff;
				border-radius: 4rpx;
				margin-right: 16rpx;
			}

			.text {
				font-size: 32rpx;
				color: #272727;
			}
		}

		.title_right {
			display: flex;
			justify-content: center;
			align-items: center;

			.right_text {
				color: #b3b3b3;
				font-size: 24rpx;
				margin-right: 7rpx;
			}
		}
	}

	.news_list {
		width: 93%;
		margin: 0 auto;
		margin-top: 34rpx;
	}

	.list_box {
		display: flex;
		border-bottom: 1px solid #e6e6e6;
		padding-bottom: 30rpx;
		margin-bottom: 30rpx;

		.box_detail {
			margin-left: 24rpx;

			.title {
				width: 472rpx;
				height: 80rpx;
				font-size: 30rpx;
				color: #323232;
				line-height: 40rpx;
				text-overflow: ellipsis;
				display: -webkit-box;
				-webkit-line-clamp: 2;
				-webkit-box-orient: vertical;
				overflow: hidden;
			}

			.detail {
				display: flex;
				margin-top: 30rpx;
				align-items: center;

				.detail_text {
					font-size: 24rpx;
					color: #b3b3b3;
					margin-left: 8rpx;
				}
			}
		}
	}

	.popup {
		position: fixed;
		left: 0;
		right: 0;
		top: 0;
		height: 100%;
		background-color: rgba(0, 0, 0, 0.6);
		z-index: 9998;
	}

	.popup-info {
		position: fixed;
		width: 600rpx;
		top: 50%;
		left: 50%;
		transform: translate(-50%, -50%);
		border-radius: 12rpx;
		background-color: #FFFFFF;
		z-index: 9999;
		padding: 0 48rpx;
		padding-top: 60rpx;
	}

	.top {
		color: #262626;
		font-size: 32rpx;
	}

	.content {
		margin-top: 40rpx;
		width: 560rpx;
		color: #808080;
		font-size: 30rpx;
		line-height: 46rpx;

		.con-center {
			display: inline-block;
			white-space: nowrap;
			width: 100%;
			overflow: hidden;
			text-overflow: ellipsis;
		}
	}

	.button {
		display: flex;
		justify-content: space-between;
		margin-top: 88rpx;
		padding-bottom: 44rpx;

		.cancel {
			color: #262626;
			font-size: 32rpx;
		}

		.update {
			font-size: 32rpx;
			color: #28b07c;
		}
	}
	.ten {
		width: 100%;
		position: absolute;
		background-color: #FFFFFF;
		height: 20rpx;
		border-radius: 20rpx 20rpx 0 0;
		margin-top: -10rpx;
	}
</style>

